package feedback.web.bean.student;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.springframework.beans.factory.annotation.Autowired;

import feedback.core.models.entities.ClassRoom;
import feedback.core.models.entities.Student;
import feedback.core.models.entities.Subject;
import feedback.core.services.EntityManagerServices;
import feedback.web.bean.admin.LoginBean;

@ManagedBean(name = "ls")
@SessionScoped
public class ListSubject {
	@Autowired
	private List<Subject> listsj = new ArrayList<Subject>();
	@Autowired
	private Subject sub = new Subject();
	@Autowired
	private Student stu = new Student();
	@Autowired
	private ClassRoom cl = new ClassRoom();
	@Autowired
	private List<ClassRoom> listCr = new ArrayList<ClassRoom>();

	@ManagedProperty("#{login}")
	private LoginBean login;
	@ManagedProperty("#{entityManager}")
	private EntityManagerServices servicesEn;

	@PostConstruct
	public void init() {

	}

	public List<Subject> getSubject() {
		try {
			if (login.isStudentIslogin()) {
				stu = (Student) login.getUserLogin();
				listCr = stu.getClassRooms();
				// List<Subject> lSubjects = new ArrayList<Subject>();
				for (ClassRoom cr : listCr) {
					listsj.add(cr.getSubject());
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return listsj;
	}

	public List<ClassRoom> getClassRoom() {
		stu = (Student) login.getUserLogin();
		return listCr = stu.getClassRooms();
	}

	public List<Subject> getListsj() {
		return listsj;
	}

	public void setListsj(List<Subject> listsj) {
		this.listsj = listsj;
	}

	public Subject getSub() {
		return sub;
	}

	public void setSub(Subject sub) {
		this.sub = sub;
	}

	public Student getStu() {
		return stu;
	}

	public void setStu(Student stu) {
		this.stu = stu;
	}

	public ClassRoom getCl() {
		return cl;
	}

	public void setCl(ClassRoom cl) {
		this.cl = cl;
	}

	public List<ClassRoom> getListCr() {
		return listCr;
	}

	public void setListCr(List<ClassRoom> listCr) {
		this.listCr = listCr;
	}

	public LoginBean getLogin() {
		return login;
	}

	public void setLogin(LoginBean login) {
		this.login = login;
	}

	public EntityManagerServices getServicesEn() {
		return servicesEn;
	}

	public void setServicesEn(EntityManagerServices servicesEn) {
		this.servicesEn = servicesEn;
	}
}
